﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Component.BLL;
using OF.Component.Model;
using OF.Component.Base;
using OF.Utility;


namespace _2010web.Manage.authority
{
    public partial class AuthorityRoleEdit : OpBasePage
    {
        protected int intID = 0;
        protected int intCID = 0;
        protected int intSystemID = 0;
        protected string strMessage = "";
        protected string strStyle= "style='display:none;'";
        protected void Page_Load(object sender, EventArgs e)
        {
            SetPageCode(101, 10104);
            if (!Page.IsPostBack)
            {
                intID = RequestUtility.GetQueryInt("ID", -1);
                intCID = RequestUtility.GetQueryInt("cid", -1);
                BindDictionary();
                if (intID > -1)
                {
                    AuthorityRoleInfo info = AuthorityRoleOperate.GetByID(intID);
                    this.txtName.Text = info.RoleName;
                    this.ddParentRole.SelectedValue = info.ParentID.ToString();
                    
                }
                else
                {
                    this.ddParentRole.SelectedValue = intCID.ToString();
                }
                this.ddParentRole.Enabled = false;
            }
        }

        private void BindDictionary()
        {
            int count = 0;
            string where = "1=1 and IsActive=1 and ParentID=0";
            IList<AuthorityRoleInfo> list = AuthorityRoleOperate.Search(out count, 1, 9999, where, "RoleID", true);
            this.ddParentRole.DataSource = list;
            this.ddParentRole.DataTextField = "RoleName";
            this.ddParentRole.DataValueField = "RoleID";
            this.ddParentRole.DataBind();
            ddParentRole.Items.Insert(0, new ListItem("一级角色", "0"));
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string MessageInfo = "信息修改成功！";
            intSystemID = RequestUtility.GetQueryInt("sysid", -1);
            intID = RequestUtility.GetQueryInt("ID", -1);
            AuthorityRoleInfo info;
            info = AuthorityRoleOperate.GetByID(intID);
            if (info == null)
            {
                info = new AuthorityRoleInfo();
            }
            AuthorityRoleInfo oldinfo = ObjectCopy<AuthorityRoleInfo>.DeepCopy(info);
            info.RoleName = txtName.Text;
            info.ParentID = EConvert.ToInt(this.ddParentRole.SelectedValue);
            info.RoleID = intID;
            info.IsActive = 1;
            info.UpdateTime = DateTime.Now;
            if (info.RoleID > 0)
            {
                AuthorityRoleOperate.Update(info);
             
            }
            else
            {
                MessageInfo = "信息创建成功！";
                info.SystemID = intSystemID;
                info.CreateDateTime = DateTime.Now;
                AuthorityRoleOperate.Insert(info);
             
            }
            strMessage = MessageDivInfo(MessageInfo, "");
        }
    }
}
